
clear
set more off
cd "/Users/michaelflynn/Dropbox/Projects/Aid and NGOs/Data"
use "ngoaiddata.dta", clear

log using ngosandaid, smcl name(ngosandaid) replace


* Variable Labels
	label var logexport "ln(Exports)"
	label var growth "Donor Growth Rate"
	label var gov_develop2 "Ideology $\times$ GDP Per Capita"
	label var percright "Percentage of Right Parties"
	label var exports_percent "Exports as $\%$ of Donor GDP"
	label var post08 "Post-Financial Crisis"
	label var growth "Donor Growth Rate"
	label var polity2 "Recipient Polity Score"
	label var physint "Recipient Physical Integrity Rights"
	label var logtrade "ln(Trade)"
	label var lndisasternum2l "Natural Disasters"
	label var defense "Alliance"
	label var s3un "UN Affinity"
	label var lnall "ln(All Aid Channels)"
	label var govtrile "Donor Government Ideology Score"
	label var govtecon "Donor Government Ideology Score"
	label var lnratio "Lagged ln(Aid Ratio)"
	label var prio2 "Recipient Civil Conflict"
	label var lnngo "ln(NGO Aid)"
	label var lnpublic "ln(Public Aid)"
	label var loggdppc "Recipient GDP Per Capita"
	label var governance_all_mean "Recipient Governance"
	
	set matsize 2000
	replace dyad = (ccode1*1000)+ccode2
	drop if dyad==.
	xtset dyad year
			

* Ratio Models
eststo clear
reg F.lnratio govtecon socgdp1Ml  growth post08 s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio, robust
/// Model 1 - Base Model
eststo: reg F.lnratio govtecon if e(sample), robust
/// Model 2 - Full Model
eststo: reg F.lnratio govtecon socgdp1Ml  growth s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio, robust
/// Model 3 - Full model with  random effects
eststo: xtreg F.lnratio govtecon socgdp1Ml  growth s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio , re robust
 

xtreg F.lnratio govtecon socgdp1Ml  growth s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio , re 
estimates store re
xtreg F.lnratio govtecon socgdp1Ml  growth s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio , fe 
estimates store fe
xtreg F.lnratio govtecon socgdp1Ml  growth s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall exports_percent colony lnratio , pa 
estimates store pa

hausman fe re
hausman re pa
hausman  fe pa

#delimit ;
	
esttab est1 est2 est3 using table_1.tex, replace	
		se(3)
		b(3) 
		star(* .10 ** .05 *** .01) 
		wide
		nogaps
		keep(govtecon  socgdp1Ml growth s3un defense exports_percent colony polity2 loggdppc governance_all_mean prio2 physint lnall lnratio)
		order(govtecon  socgdp1Ml growth s3un defense exports_percent colony polity2 loggdppc governance_all_mean prio2 physint lnall lnratio)
		compress
		label 
		nonotes
		mtitles("Base Model" "OLS Model" "Random Effects")  
		addnote("Robust standard errors in parentheses." "$*$ p$\leq$ 0.10 $**$ p$\leq$ 0.05, $***$ p$\leq$0.01")
		;		
		#delimi cr
		
		
		
* Seemingly Unrelated Regression Models		
eststo clear

/// Model 1 - No Fixed Effects
eststo: sureg (F.lnngo lnngo  growth  govtecon  colony s3un defense prio2  polity2 loggdppc governance_all_mean socgdp1Ml exports_percent physint lnall) ///
			  (F.lnpublic lnpublic  growth  govtecon  colony s3un defense prio2  polity2 loggdppc governance_all_mean socgdp1Ml exports_percent physint lnall), corr

/// Model 2 - Fixed Effects
eststo: sureg (F.lnngo lnngo growth  govtecon  colony s3un defense prio2 polity2 loggdppc governance_all_mean socgdp1Ml exports_percent physint lnall i.ccode2) ///
		      (F.lnpublic lnpublic  growth  govtecon  colony s3un defense prio2  polity2 loggdppc governance_all_mean socgdp1Ml exports_percent physint lnall i.ccode2), corr

			  #delimit ;
	
esttab est1 est2 using table_2.tex, replace	
		se(3)
		b(3) 
		star(* .10 ** .05 *** .01) 
		wide
		nogaps
		mtitles
		scalars("chi2_bp $\chi^2$" )
		compress
		keep(govtecon  socgdp1Ml growth s3un defense exports_percent colony polity2 governance_all_mean prio2 physint loggdppc lnall lnngo lnpublic)
		order(govtecon  socgdp1Ml growth s3un defense exports_percent colony polity2 governance_all_mean prio2 physint loggdppc lnall lnngo lnpublic)
		label 
		nonotes
		equations(1,2)
		mtitles("No Fixed Effects" "Recipient FE")
		eqlabels("\emph{NGO Aid Equation}" "\emph{Public Sector Aid Equation}")
		addnote("Standard errors in parentheses." "$*$ p$\leq$ 0.10 $**$ p$\leq$ 0.05, $***$ p$\leq$0.01")
		;		
		
esttab est1 est2 using table_2SHORT.tex, replace	
		se(3)
		b(3) 
		star(* .10 ** .05 *** .01) 
		wide
		nogaps
		mtitles
		scalars("chi2_bp $\chi^2$" )
		compress
		keep(govtecon)
		order(govtecon)
		label 
		nonotes
		equations(1,2)
		mtitles("No Fixed Effects" "Recipient FE")
		eqlabels("\emph{NGO Aid Equation}" "\emph{Public Sector Aid Equation}")
		addnote("Standard errors in parentheses." "$*$ p$\leq$ 0.10 $**$ p$\leq$ 0.05, $***$ p$\leq$0.01")
		;		
		#delimit cr
		
		
		
	
/// Ratio Models with Conditional Effects

eststo clear
/// Model 1 - Exports
eststo: xtreg F.lnratio c.govtecon##c.exports_percent socgdp1Ml growth post08 s3un defense physint polity2 loggdppc governance_all_mean prio2 lnall colony lnratio, re robust
/// Model 2 - Affinity
eststo: xtreg F.lnratio c.govtecon##c.s3un socgdp1Ml growth post08 defense physint polity2 loggdppc governance_all_mean prio2 lnall c.exports_percent colony lnratio, re robust
/// Model 3 - Defense
eststo: xtreg F.lnratio c.govtecon defense gov_defense socgdp1Ml growth post08 s3un physint polity2 loggdppc governance_all_mean prio2 lnall c.exports_percent colony lnratio, re robust
/// Model 4 - Governance
eststo: xtreg F.lnratio c.govtecon##c.governance_all_mean socgdp1Ml growth post08 s3un defense physint polity2 loggdppc prio2 lnall c.exports_percent colony lnratio, re robust
/// Model 5 - Physical Integrity Rights
eststo: xtreg F.lnratio c.govtecon##c.physint socgdp1Ml growth post08 s3un defense polity2 loggdppc governance_all_mean prio2 lnall c.exports_percent colony lnratio, re robust
/// Model 6 - Development
eststo: xtreg F.lnratio c.govtecon##c.loggdppc socgdp1Ml growth post08 s3un defense physint polity2 governance_all_mean prio2 lnall c.exports_percent colony lnratio, re robust


#delimit ;
	
esttab est1 est2 est3 est4 est5 est6 using table_3.tex, replace	
		se(3)
		b(3) 
		star(* .10 ** .05 *** .01) 
		wide
		substitute(  )
		nogaps
		nobaselevels
		noomitted
		compress
		label 
		nonotes
		mtitles("Exports" "Affinity" "Alliance" "Governance" "Human Rights" "Development") 
		order(govtecon exports_percent s3un defense governance_all_mean physint loggdppc c.govtecon#c.exports_percent c.govtecon#c.s3un gov_defense c.govtecon#c.governance_all_mean c.govtecon#c.physint c.govtecon#c.loggdppc socgdp1Ml growth colony polity2 prio2 post08 lnall lnratio)
		addnote("Robust standard errors in parentheses." "$*$ p$\leq$ 0.10 $**$ p$\leq$ 0.05, $***$ p$\leq$0.01")
		;		
		#delimi cr
		
		
log close ngosandaid
